import { createApp } from 'vue';
import { createPinia } from 'pinia';
import * as echarts from  'echarts'
import VueECharts from 'vue-echarts'
import App from './App.vue';
import router from './router';
import { usePermissStore } from './store/permiss';
import 'element-plus/dist/index.css';
import './assets/css/icon.css';
// @ts-ignore
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import { graphic } from 'echarts/index';
//wujie
import WujieVue from "wujie-vue3";
import {hostMap} from "./wj/hostMap";
import {fetch} from "./wj/fetch";
const { bus, setupApp, preloadApp, destroyApp } = WujieVue;

const app = createApp(App);
app.use(createPinia());
app.use(router);
app.provide('graphic', graphic);
app.use(WujieVue)
//引入数据分析图表库
app.component("v-chart",VueECharts)
// 注册elementplus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
// 自定义权限指令
const permiss = usePermissStore();
app.directive('permiss', {
    mounted(el, binding) {
        if (!permiss.key.includes(String(binding.value))) {
            el['hidden'] = true;
        }
    },
});


const degrade = window.localStorage.getItem("degrade") === "true" || !window.Proxy || !window.CustomElementRegistry;
const props = {
    jump: (name: any) => {
        router.push({ name });
    },
};

setupApp({
    name: "vue3",
    url: hostMap("//localhost:8080/"),
    exec: true,
    alive: true,
    // plugins: [{ cssExcludes: ["https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"] }],
    props,
    fetch: (url, options) =>
        window.fetch(url, options),
    degrade,
});

app.mount('#app');